import { formatGMTDate, toPercent, compareObject } from '../../../../assets/js/util.js'
import echarts from 'echarts'
export default {
    data() {
        return {
            // loading
            loading: true,
            // 默认参数 和 URL
            SRC: '',
            DP: {
                p: '',
                f: ''
            },
            // title
            title: "渠道累计付费",
            xlsxTitle: '',
            /* 的宽*/
            pageWidth: '100%',
            pickerOptions: {
                shortcuts: [{
                    text: '最近7天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近15天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 15);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近30天',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            tableHeaderAll21: [
                { "prop": "dateStr", "label": "日期", 'width': '120px', 'fixed': true },
                { "prop": "platformName", "label": "平台", 'width': '120px', 'fixed': false },
                { "prop": "channelName", "label": "渠道", 'width': '120px', 'fixed': false },
                { "prop": "income1", "label": "1日收入", 'width': '130px', 'fixed': false },
                { "prop": "income2", "label": "2日收入", 'width': '130px', 'fixed': false },
                { "prop": "income3", "label": "3日收入", 'width': '130px', 'fixed': false },
                { "prop": "income4", "label": "4日收入", 'width': '130px', 'fixed': false },
                { "prop": "income5", "label": "5日收入", 'width': '130px', 'fixed': false },
                { "prop": "income6", "label": "6日收入", 'width': '130px', 'fixed': false },
                { "prop": "income7", "label": "7日收入", 'width': '130px', 'fixed': false },
                { "prop": "income8", "label": "8日收入", 'width': '130px', 'fixed': false },
                { "prop": "income9", "label": "9日收入", 'width': '130px', 'fixed': false },
                { "prop": "income10", "label": "10日收入", 'width': '130px', 'fixed': false },
                { "prop": "income11", "label": "11日收入", 'width': '130px', 'fixed': false },
                { "prop": "income12", "label": "12日收入", 'width': '130px', 'fixed': false },
                { "prop": "income13", "label": "13日收入", 'width': '130px', 'fixed': false },
                { "prop": "income14", "label": "14日收入", 'width': '130px', 'fixed': false },
                { "prop": "income15", "label": "15日收入", 'width': '130px', 'fixed': false },
                { "prop": "income16", "label": "16日收入", 'width': '130px', 'fixed': false },
                { "prop": "income17", "label": "17日收入", 'width': '130px', 'fixed': false },
                { "prop": "income18", "label": "18日收入", 'width': '130px', 'fixed': false },
                { "prop": "income19", "label": "19日收入", 'width': '130px', 'fixed': false },
                { "prop": "income20", "label": "20日收入", 'width': '130px', 'fixed': false },
                { "prop": "income21", "label": "21日收入", 'width': '130px', 'fixed': false },
                { "prop": "income22", "label": "22日收入", 'width': '130px', 'fixed': false },
                { "prop": "income23", "label": "23日收入", 'width': '130px', 'fixed': false },
                { "prop": "income24", "label": "24日收入", 'width': '130px', 'fixed': false },
                { "prop": "income25", "label": "25日收入", 'width': '130px', 'fixed': false },
                { "prop": "income26", "label": "26日收入", 'width': '130px', 'fixed': false },
                { "prop": "income27", "label": "27日收入", 'width': '130px', 'fixed': false },
                { "prop": "income28", "label": "28日收入", 'width': '130px', 'fixed': false },
                { "prop": "income29", "label": "29日收入", 'width': '130px', 'fixed': false },
                { "prop": "income30", "label": "30日收入", 'width': '130px', 'fixed': false },
                { "prop": "income31", "label": "31日收入", 'width': '130px', 'fixed': false },
                { "prop": "income32", "label": "32日收入", 'width': '130px', 'fixed': false },
                { "prop": "income33", "label": "33日收入", 'width': '130px', 'fixed': false },
                { "prop": "income34", "label": "34日收入", 'width': '130px', 'fixed': false },
                { "prop": "income35", "label": "35日收入", 'width': '130px', 'fixed': false },
                { "prop": "income36", "label": "36日收入", 'width': '130px', 'fixed': false },
                { "prop": "income37", "label": "37日收入", 'width': '130px', 'fixed': false },
                { "prop": "income38", "label": "38日收入", 'width': '130px', 'fixed': false },
                { "prop": "income39", "label": "39日收入", 'width': '130px', 'fixed': false },
                { "prop": "income40", "label": "40日收入", 'width': '130px', 'fixed': false },
                { "prop": "income41", "label": "41日收入", 'width': '130px', 'fixed': false },
                { "prop": "income42", "label": "42日收入", 'width': '130px', 'fixed': false },
                { "prop": "income43", "label": "43日收入", 'width': '130px', 'fixed': false },
                { "prop": "income44", "label": "44日收入", 'width': '130px', 'fixed': false },
                { "prop": "income45", "label": "45日收入", 'width': '130px', 'fixed': false },
                { "prop": "income46", "label": "46日收入", 'width': '130px', 'fixed': false },
                { "prop": "income47", "label": "47日收入", 'width': '130px', 'fixed': false },
                { "prop": "income48", "label": "48日收入", 'width': '130px', 'fixed': false },
                { "prop": "income49", "label": "49日收入", 'width': '130px', 'fixed': false },
                { "prop": "income50", "label": "50日收入", 'width': '130px', 'fixed': false },
                { "prop": "income51", "label": "51日收入", 'width': '130px', 'fixed': false },
                { "prop": "income52", "label": "52日收入", 'width': '130px', 'fixed': false },
                { "prop": "income53", "label": "53日收入", 'width': '130px', 'fixed': false },
                { "prop": "income54", "label": "54日收入", 'width': '130px', 'fixed': false },
                { "prop": "income55", "label": "55日收入", 'width': '130px', 'fixed': false },
                { "prop": "income56", "label": "56日收入", 'width': '130px', 'fixed': false },
                { "prop": "income57", "label": "57日收入", 'width': '130px', 'fixed': false },
                { "prop": "income58", "label": "58日收入", 'width': '130px', 'fixed': false },
                { "prop": "income59", "label": "59日收入", 'width': '130px', 'fixed': false },
                { "prop": "income60", "label": "60日收入", 'width': '130px', 'fixed': false },
                { "prop": "income61", "label": "61日收入", 'width': '130px', 'fixed': false },
                { "prop": "income62", "label": "62日收入", 'width': '130px', 'fixed': false },
                { "prop": "income63", "label": "63日收入", 'width': '130px', 'fixed': false },
                { "prop": "income64", "label": "64日收入", 'width': '130px', 'fixed': false },
                { "prop": "income65", "label": "65日收入", 'width': '130px', 'fixed': false },
                { "prop": "income66", "label": "66日收入", 'width': '130px', 'fixed': false },
                { "prop": "income67", "label": "67日收入", 'width': '130px', 'fixed': false },
                { "prop": "income68", "label": "68日收入", 'width': '130px', 'fixed': false },
                { "prop": "income69", "label": "69日收入", 'width': '130px', 'fixed': false },
                { "prop": "income70", "label": "70日收入", 'width': '130px', 'fixed': false },
                { "prop": "income71", "label": "71日收入", 'width': '130px', 'fixed': false },
                { "prop": "income72", "label": "72日收入", 'width': '130px', 'fixed': false },
                { "prop": "income73", "label": "73日收入", 'width': '130px', 'fixed': false },
                { "prop": "income74", "label": "74日收入", 'width': '130px', 'fixed': false },
                { "prop": "income75", "label": "75日收入", 'width': '130px', 'fixed': false },
                { "prop": "income76", "label": "76日收入", 'width': '130px', 'fixed': false },
                { "prop": "income77", "label": "77日收入", 'width': '130px', 'fixed': false },
                { "prop": "income78", "label": "78日收入", 'width': '130px', 'fixed': false },
                { "prop": "income79", "label": "79日收入", 'width': '130px', 'fixed': false },
                { "prop": "income80", "label": "80日收入", 'width': '130px', 'fixed': false },
                { "prop": "income81", "label": "81日收入", 'width': '130px', 'fixed': false },
                { "prop": "income82", "label": "82日收入", 'width': '130px', 'fixed': false },
                { "prop": "income83", "label": "83日收入", 'width': '130px', 'fixed': false },
                { "prop": "income84", "label": "84日收入", 'width': '130px', 'fixed': false },
                { "prop": "income85", "label": "85日收入", 'width': '130px', 'fixed': false },
                { "prop": "income86", "label": "86日收入", 'width': '130px', 'fixed': false },
                { "prop": "income87", "label": "87日收入", 'width': '130px', 'fixed': false },
                { "prop": "income88", "label": "88日收入", 'width': '130px', 'fixed': false },
                { "prop": "income89", "label": "89日收入", 'width': '130px', 'fixed': false },
                { "prop": "income90", "label": "90日收入", 'width': '130px', 'fixed': false }
            ],
            tableData21: [],
            tableDataAll21: [],
            date: '',
            // 请求参数
            postObj: {
                dstart: '',
                dend: ''
            },
            // 变成分数
            pencent(data) {
                //转换为%比 
                var arr = ['activePayRadio', 'the2Left', 'the3Left', 'the7Left', 'the14Left', 'the30Left', 'loginNewUservalidatedRadio', 'loginRadio', 'loginRadio2']
                for (var i = 0; i < data.length; i++) {
                    for (var j in data[i]) {
                        for (var n = 0; n < arr.length; n++) {
                            if (j === arr[n]) {
                                if (data[i][j] == 0) { data[i][j] = "" } else { data[i][j] = toPercent(data[i][j]); }
                            }
                        }
                    }
                }
                return data
            },
            // 分页一
            page1: {
                /*当前页显示数量*/
                pageSize: 15,
                /*每页显示的数量*/
                pageSizes: [10, 15, 50, 100],
                /*dataTotal表数量*/
                dataTotal: 0,
                /*分页器*/
                currentPage: 1,
            },
        }
    },
    methods: {
        // 通用 成功 与 失败
        successFun(data) {
            this.$message({
                message: data,
                type: 'success'
            });
        },
        errorFun(data) {
            this.$message.error(data);
        },
        // 表格下载
        excel(tableIndex, sheet) {
            var that = this;
            that.xlsxTitle = sheet + "-" + that.postObj.dstart + "到" + that.postObj.dend;
            that.downloadExl(that['tableHeader' + tableIndex], that['tableData' + tableIndex], that.xlsxTitle, sheet)
        },
        // 时间改变 得到起始时间和结束时间
        dateChange(val) {
            if (val === undefined || val === '') {
                this.errorFun('请选择查看时间！')
            } else {
                var t = val.split(' - ')
                this.postObj.dstart = t[0];
                this.postObj.dend = t[1];
                if (this.tableDataAll21.length !== 0) {
                    this.getData(this.postObj);
                }
            }
        },
        handleSizeChange1(val) {
            this.page1.pageSize = val;
            this.tableControl1();
        },
        handleCurrentChange1(val) {
            this.page1.currentPage = val;
            this.tableControl1();
        },
        tableControl1() {
            this.tableData21 = this.tableDataAll21.slice((this.page1.currentPage - 1) * this.page1.pageSize, this.page1.currentPage * this.page1.pageSize);
        },
        // 获取数据
        /*'ps': `dstart=${data.dstart}&dend=${data.dend
        			}*/
        getData(data) {
            var that = this;
            // that.loading = true;
            var p = new Promise(function(resolve, reject) {
                that.$http.jsonp(`${that.SRC}data/get.do?p=${that.DP.p}&f=${that.DP.f}&a=search`, {
                    params: { 'ps': `dstart=${data.dstart}&dend=${data.dend}` }
                }).then(function(res) {
                    resolve(res.body)
                })
            })
            p.then(function(value) {
                that.tableData1 = [];
                var data = JSON.parse(value)
                var d = JSON.parse(data.replace(/\"\{\"/g, '\{\"').replace(/\"\}\"/g, '\"\}'));
                if (parseInt(d["res"]) === 0) {
                    that.loading = false;
                    console.log(d.channelPayDatas)
                    that.page1.dataTotal = d.channelPayDatas.length;
                    that.tableDataAll21 = d.channelPayDatas;
                    that.tableDataAll21.sort(compareObject('dateStr', true));
                    that.tableControl1();

                } else {
                    // that.getErrorMsg(Number(d.res))
                }
            })
        },
        // 表格排序
        sortChange(column) {
            if (column.prop === null) {
                return;
            } else if (column.order === 'descending') {
                this.tableDataAll21.sort(compareObject(column.prop, false));
            } else { //正序
                this.tableDataAll21.sort(compareObject(column.prop, true));
            }
            this.tableControl1();
        }
    },
    computed: {},
    mounted() {
        // 初始化URL
        this.SRC = this.$store.getters.src;
        this.DP.p = localStorage.getItem('ZULONGBIPROJECTID');
        this.DP.f = localStorage.getItem('ZULONGBIPAGEID');
        this.date = [new Date(new Date().getTime() - 16 * 86400000), new Date(new Date().getTime() - 86400000)];
        this.postObj.dstart = formatGMTDate(new Date().getTime() - 86400000 * 16, true);
        this.postObj.dend = formatGMTDate(new Date().getTime() - 86400000, true);
        this.getData(this.postObj);
    }
}